package com.bgds.sys.task;

import com.bgds.sys.api.service.DeTongService;
import com.bgds.sys.common.utils.ResultUtil;
import com.bgds.sys.module.controller.BaseBaoxing;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author Smiling
 * @description: 除尘风机总貌推送任务（振动和温度）
 * @date 2021/5/24  22:14
 */
@Slf4j
@Component
public class DedustFanJob implements Job {
    @Autowired
    private SimpMessagingTemplate messagingTemplate;
    @Autowired
    private DeTongService deTongService;
    @Autowired
    private BaseBaoxing baseBaoxing;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
//        Map<String, List<DataTimeSerise>> newMap = new HashMap<>(2);
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        String relationId = dataMap.get("relationId").toString();
        String deviceCode = dataMap.get("deviceCode").toString();
        String id = dataMap.get("id").toString();
        log.info("除尘风机总貌推送任务:{}",dataMap);
        Map map = new HashMap();
        map.put("baoxing", baseBaoxing.all(deviceCode));
        map.put("detong", baseBaoxing.getObject(relationId,107));
        messagingTemplate.convertAndSendToUser(id, "/dedust_fan", new ResultUtil<>().setData(map));
    }
}